package com.qingcheng.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.qingcheng.entity.PageResult;
import com.qingcheng.entity.Result;
import com.qingcheng.goods.BrandService;
import com.qingcheng.pojo.goods.Brand;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Reference
    private BrandService brandService;


    //查询所有
    @RequestMapping("/findAll")
    public List<Brand> findAll() {
        return brandService.findAll();
    }

    /**
     * 分页查询
     *
     * @param page 页码
     * @param size 每页记录数
     * @return 分页结果
     */
    @RequestMapping("/pageAll")
    public PageResult<Brand> pageAll(int page, int size) {

        return brandService.findPage(page, size);

    }

    //条件查询
    @RequestMapping("/findList")
    public List<Brand> findList(@RequestBody Map<String, Object> searchMap) {

        return brandService.findList(searchMap);

    }

    /*条件分页查询*/
    @RequestMapping("/findPage")
    public PageResult<Brand> findPage(@RequestBody Map<String, Object> map, int page, int size) {

        return brandService.findPge(map, page, size);

    }
    //根据Id查询()
    @GetMapping("/findById")
    public Brand findById(Integer id){
        Brand byIdBrand = brandService.findById(id);
        return byIdBrand;
    }

    //添加一个商品信息
    @PostMapping("/addBrand")
    public Result addBrand(@RequestBody Brand brand){
        brandService.addBrand(brand);

        return new Result();
    }
    //修改一个
    @PostMapping("/updateBrand")
    public Result updateBrand(@RequestBody Brand brand){
        brandService.updateBrand(brand);

        return new Result();
    }
    //根据Id删除一个
    @GetMapping("/deleteBrandById")
    public Result deleteBrandById(Integer id){
        brandService.deleteByBrand(id);
      return   new Result();

    }
}
